package com.msmall.community.admin.action;

import java.io.File;

import com.msmall.base.action.HTMLBaseAction;
import com.msmall.base.util.ConstantDB;
import com.msmall.community.keyword.model.Keyword;
import com.msmall.community.keyword.service.KeywordManager;

public class KeywordAction extends HTMLBaseAction {

	private static final long serialVersionUID = 8395050717467271917L;

	private Long keywordid;
	
	private String keywordids;
	
	/**
	 * 当推荐需要图片时，上传
	 */
	private File image;
	private String imageContentType; // 文件的内容类型
	private String imageFileName; // 上传文件名
	
	private Keyword keyword;
	
	private KeywordManager keywordManager;

	public String execute(){
		return SUCCESS;
	}
	public String query(){
		try{
		page.setPageSize(1000);
		page.setClazz(Keyword.class);
		StringBuffer buffer = new StringBuffer();
		buffer.append(" from Keyword where 1=1 ");
		if(keyword != null){
			if(keyword.getModule() > 0){
				buffer.append(" and module=").append(keyword.getModule());
			}
		}
		page.setQueryString(buffer.toString());
		keywordManager.getPagination(page);
		}catch(Exception e){
			log.debug(e);
		}
		return SUCCESS;
	}
	public String create(){
		return SUCCESS;
	}
	public String update(){
		keyword = (Keyword) keywordManager.get(Keyword.class, keywordid);
		return SUCCESS;
	}
	
	public String save(){
		if(keyword.getEnabled() == null){
			keyword.setEnabled(ConstantDB.UNAVALIABLE);
		}
		keywordManager.addKeyword(image, imageFileName, keyword, getUserid(), getUserAgentType());
		return SUCCESS;
	}
	public String remove(){
		keywordManager.removeKeywords(keywordids, getUserid());
		return SUCCESS;
	}
	public Long getKeywordid() {
		return keywordid;
	}
	public void setKeywordid(Long keywordid) {
		this.keywordid = keywordid;
	}
	public String getKeywordids() {
		return keywordids;
	}
	public void setKeywordids(String keywordids) {
		this.keywordids = keywordids;
	}
	public File getImage() {
		return image;
	}
	public void setImage(File image) {
		this.image = image;
	}
	public String getImageContentType() {
		return imageContentType;
	}
	public void setImageContentType(String imageContentType) {
		this.imageContentType = imageContentType;
	}
	public String getImageFileName() {
		return imageFileName;
	}
	public void setImageFileName(String imageFileName) {
		this.imageFileName = imageFileName;
	}
	public Keyword getKeyword() {
		return keyword;
	}
	public void setKeyword(Keyword keyword) {
		this.keyword = keyword;
	}
	public void setKeywordManager(KeywordManager keywordManager) {
		this.keywordManager = keywordManager;
	}
}